package com.hospital.pony.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hospital.LoginActivity;
import com.hospital.MyApplyActivity;
import com.hospital.NewsListActivity;
import com.hospital.PersonApplyActivity;
import com.hospital.PersonListActivity;
import com.hospital.R;
import com.hospital.UserActivity;
import com.hospital.pony.base.BaseFragment;
import com.hospital.pony.db.MemberUserUtils;

import io.rong.imlib.RongIMClient;

/**
 * 
 * @author WangXuan
 * 
 */
public class MeFragment extends BaseFragment {

	// 获取view
	private View rootView;
	private RelativeLayout mtvUser;
	private RelativeLayout mtvSoft;

	private TextView yuyueinfor;
	private RelativeLayout mrlMyDisease;

	private RelativeLayout mrlAddFriend;
	private RelativeLayout mrlDeleteFriend;
	


	@Override
	public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		rootView = LayoutInflater.from(requireActivity()).inflate(R.layout.fragment_doctorcontent, null);
		initWidget();
		initData();
		return rootView;
	}

	/**
	 * 获取控件
	 */
	@Override
	public void initWidget() {

		yuyueinfor = (TextView) rootView.findViewById(R.id.yuyueinfor);
		mrlDeleteFriend = (RelativeLayout) rootView.findViewById(R.id.mrlDeleteFriend);
		mrlDeleteFriend.setOnClickListener(this);
		
		mrlAddFriend = (RelativeLayout) rootView.findViewById(R.id.mrlAddFriend);
		mrlMyDisease = (RelativeLayout) rootView.findViewById(R.id.mrlMyDisease);
		mtvSoft = (RelativeLayout) rootView.findViewById(R.id.mtvSoft);
		mtvUser = (RelativeLayout) rootView.findViewById(R.id.mtvUser);
		mtvUser.setOnClickListener(this);
		mtvSoft.setOnClickListener(this);
		mrlAddFriend.setOnClickListener(this);
		mrlMyDisease.setOnClickListener(this);

	}

	/**
	 * 处理点击事件
	 */
	@Override
	public void onClick(View v) {

		if(v.getId()== R.id.mrlDeleteFriend){
			Intent mrlDeleteFriend = new Intent(requireActivity(), PersonListActivity.class);
			requireActivity().startActivity(mrlDeleteFriend);
		}
		if(v.getId()== R.id.mrlAddFriend){
			Intent mrlAddFriend = new Intent(requireActivity(), NewsListActivity.class);
			requireActivity().startActivity(mrlAddFriend);
		}
		if(v.getId()== R.id.mrlMyDisease){
			if(MemberUserUtils.getLoginFlag(requireActivity()).equals("1")){
				Intent mrlReview = new Intent(requireActivity(), MyApplyActivity.class);
				requireActivity().startActivity(mrlReview);
			}else{
				Intent mrlReview = new Intent(requireActivity(), PersonApplyActivity.class);
				requireActivity().startActivity(mrlReview);
			}
		}

		if(v.getId()== R.id.mtvSoft){

			RongIMClient.getInstance().logout();
			RongIMClient.getInstance().disconnect();
			MemberUserUtils.setUid(requireActivity(),"");


			Intent intent = new Intent(requireActivity(), LoginActivity.class);
			startActivity(intent);
			requireActivity().finish();
		}
		if(v.getId()== R.id.mtvUser){
			Intent mtvUser = new Intent(requireActivity(), UserActivity.class);
			requireActivity().startActivity(mtvUser);
		}
	}

	/**
	 * 处理数据
	 */
	@Override
	public void initData() {

		if(MemberUserUtils.getLoginFlag(requireActivity()).equals("1")){
			yuyueinfor.setText("我的预约");
		}else{
			yuyueinfor.setText("患者预约");
		}
	}

	@Override
	public void onResume() {
		super.onResume();

	}
}
